/*
 * Copyright (c) 2023 iQi.Co.Ltd. All rights reserved.
 */
 
using IQIGame.Onigao.Framework;
using System.Collections.Generic;
using System.Linq;
using System;
using NetProtocol.Enum;

namespace NetProtocol.POD {

	/// <summary>
	///  逻辑服通知保存关卡
	/// module : structs_internal
	/// </summary>
	public class NotifySaveLevelPOD : IPOD 
    {
        public readonly static Func<NotifySaveLevelPOD> FACTORY = () => new NotifySaveLevelPOD();
		public static Func<NotifySaveLevelPOD> DynamicFactory = FACTORY;
        
		/*-- members --*/
		/// <summary>
        /// 
        /// </summary>
		public long levelId;
		/// <summary>
        /// 
        /// </summary>
		public long pid;
		/// <summary>
        /// 注意, 每个服务器运行时类型不一样, 逻辑服序列化前是LevelSavePOD,序列化为bytes传输, 游戏服反序列化为byte[]
        /// </summary>
        public object saveData;
        public static Action<object, SOutputStream> Serial_saveData;
        public static Func<SInputStream, object> UnSerial_saveData;
		/// <summary>
        /// 
        /// </summary>
		public int levelCid;
		
		
		
		/*-- constructors --*/
		public NotifySaveLevelPOD() {}
		public NotifySaveLevelPOD(long levelId, long pid, object saveData, int levelCid) {
			this.levelId = levelId;
			this.pid = pid;
			this.saveData = saveData;
			this.levelCid = levelCid;
		}
	      public void Serial(SOutputStream _out) {
            _out.Write_long(levelId);
            _out.Write_long(pid);
            Serial_saveData.Invoke(saveData, _out);
            _out.Write_int(levelCid);
        }
        
        public void UnSerial(SInputStream _in) {
            if(!_in.HasRemaining()) return;
            levelId = _in.Read_long();
            if(!_in.HasRemaining()) return;
            pid = _in.Read_long();
            if(!_in.HasRemaining()) return;
            saveData = UnSerial_saveData.Invoke(_in);
            if(!_in.HasRemaining()) return;
            levelCid = _in.Read_int();
        }
		
		public NotifySaveLevelPOD Clone() {
            NotifySaveLevelPOD o = DynamicFactory();
            o.levelId = levelId;
            o.pid = pid;
            o.saveData = saveData;
            o.levelCid = levelCid;
            return o;
        }
        
        public void Clear() {
            levelId = default;
            pid = default;
            saveData = default;
            levelCid = default;
        }
		
        public override string ToString() {
			string str = "";
			str += "NotifySaveLevelPOD [";
			str += "levelId=";
			str += levelId;
			str += ", pid=";
			str += pid;
			str += ", saveData=";
			str += saveData;
			str += ", levelCid=";
			str += levelCid;
			str += "]";
			return str;
		}
		
	}
}